﻿using System.Web;
using Autofac;
using Limestone;
using Limestone.Storage.XML;

namespace LimestoneMVC.Configuration
{
    public class LimestoneModule : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<PageProvider>().As<IPageProvider>();
            builder.RegisterType<TemplateProvider>().As<ITemplateProvider>();
            builder.RegisterType<PageStubCache>().As<IPageStubCache>();

            builder.Register(c =>
                new GetCurrentUserFromHttpContext(HttpContext.Current)).As<IGetCurrentUserId>();

            builder.Register(c =>
                new XmlStorage(HttpContext.Current.Server.MapPath("/Pages/"),
                               HttpContext.Current.Server.MapPath("/Templates/"),
                               HttpContext.Current.Server.MapPath("/Trashcan/"),
                               new GetCurrentUserFromHttpContext(HttpContext.Current))).As<IStorage>();

        }
    }
}